package com.heima.admin.controller.v1;

import com.heima.model.admin.dtos.SensitiveDto;
import com.heima.model.admin.pojos.AdSensitive;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.admin.service.AdSensitiveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "敏感词管理", tags = "敏感词管理API")
@RequestMapping("/api/v1/sensitive")
public class AdSensitiveController{

    @Autowired
    private AdSensitiveService adSensitiveService;


    /**
     * 敏感词添加
     * @param adSensitive
     * @return
     */
    @PostMapping("save")
    @ApiOperation("敏感词添加")
    public ResponseResult addSensitive(@RequestBody AdSensitive adSensitive){

        return adSensitiveService.insert(adSensitive);
    }

    @PutMapping
    @ApiOperation("敏感词修改")
    public ResponseResult update(@RequestBody AdSensitive adSensitive){

        return adSensitiveService.updateSensitive(adSensitive);
    }

    /**
     * (根据name)对敏感词进行分页查询
     * @param sensitiveDto
     * @return ResponseResult
     */
    @PostMapping("/list")
    @ApiOperation("敏感词查询")
    public ResponseResult findSensitiveByName(@RequestBody SensitiveDto sensitiveDto){
        return adSensitiveService.selectSensitiveList(sensitiveDto);
    }

    /**
     * 根据id删除敏感词
     * @param id
     * @return ResponseResult
     */
    @DeleteMapping("/{id}")
    @ApiOperation("敏感词删除")
    public ResponseResult deleteById(@PathVariable Integer id){
        return adSensitiveService.deleteSensitiveById(id);
    }
}